package com.fan.shop.businesslogic;

import org.apache.log4j.Logger;

import com.fan.shop.domain.Location;
import com.fan.shop.global.ShopGlobalVariables;
import com.fan.shop.process.ProcExec;
import com.fan.shop.services.LocationService;

public class LocationCreateProcess extends ProcExec<Integer> {

	private static Logger logger = Logger
			.getLogger(LocationCreateProcess.class);
	private LocationService locationService;
	private int id;
	private String city;
	private String state;
	private String country;
	private String errorMessage;

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		LocationCreateProcess.logger = logger;
	}

	public LocationService getLocationService() {
		return locationService;
	}

	public void setLocationService(LocationService locationService) {
		this.locationService = locationService;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	

	@Override
	public Integer processImpl() {
		Location location = new Location();
		location.setCity(city);
		location.setState(state);
		location.setCountry(country);
		if(locationService.exists(location))
		{
			errorMessage = "Same Location already exists!";
			return ShopGlobalVariables.FAILED;
		}
		else
		{
			locationService.addLocation(location);
			id = location.getId();
			return ShopGlobalVariables.SUCCESS;
		}
	}

}
